<?php

require('init.php');

require(LIBWWWDIR . '/header.php');
require(LIBWWWDIR . '/forms.php');

echo "<h1>Problems Set</h1>\n\n";



if( strcmp(now(), $cdata['starttime']) >= 0 && strcmp(now(), $cdata['endtime']) < 0){

	$res = $DB->q('TABLE SELECT probid,color FROM problem WHERE cid = %i',$cdata['cid']);
	
	if( count($res) == 0 ){
		echo "No problems defined";
	}
	//mostrar problemas a teamas permitidos de acuerdo al tipo de contest
	$postmara = $cdata['post'];
	$inner = $cdata['inner'];
	$categoryid = $teamdata['categoryid'];
	$affilid = $teamdata['affilid'];
	$enable = $teamdata['enable'];

	//si se trata de un (external contest)
	if( $postmara == '0' AND $inner == '0' ) 
	{
		//deshabilitar teams tipo post; teams tipo participants externos con campo enable=0
	if( $categoryid == '4'  OR ( $categoryid == '1' AND $affilid != 'UTP' AND $enable != '1' ) )
	{
		echo "<p class=\"nodata\">No estás habilitado para este contest</p>\n";
		require(LIBWWWDIR . '/footer.php');
		exit;	
	}
	}

	//si se trata de Inner_contest
	if( $postmara == '0' AND $inner == '1'  ) 
	{
		//deshabilitar teams tipo post; teams tipo participants externos
		if( $categoryid == '4'  OR ( $categoryid == '1' AND $affilid != 'UTP') )
		{
			echo "<p class=\"nodata\">No estás habilitado para este contest</p>\n";
			require(LIBWWWDIR . '/footer.php');
			exit;	
		}	
	}

	//si se trata de una postamaraton
	if( $postmara == '1' AND $inner == '0')
	{
		//deshabilitar todo team que no sea tipo post
		if( $categoryid != '4')
		{
			echo $team;
			echo "<p class=\"nodata\">No eres usuario post</p>\n";
			require(LIBWWWDIR . '/footer.php');
			exit;
		}
	}

        echo   "<table class=\"list sortable\">\n<thead>\n" .
        "<tr><th scope=\"col\">Problem</th>" .  
        "<th scope=\"col\">Statement</th>" .
         "</tr></thead>\n<tbody>\n"; 

         foreach( $res as $row )
	{        
         	echo  '<tr><td class="probid">' .
         	( !empty($row['color']) ?
         	 '<img style="background-color: ' . htmlspecialchars($row['color']) .
                 ';" alt="problem colour ' . htmlspecialchars($row['color']) .
                 '" src="../images/circle.png" /> ' : '' ) . 
                 htmlspecialchars($row['probid']) .'</td><td>'. 
                 show_pdf( $row['probid'],  $conn_db1, $conn_db2, $cdata['cid']).' </td></tr>';   
        }
        echo "</tbody>\n</table>\n\n";
}else{

	echo "<p class=\"nodata\">No contest active yet</p>\n";
}
 
?>
